﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    
    internal class Program
    {
        static void Main(string[] args)
        {
            int[] array = { 32, 40, 55, 12, 34, 66, 71, 23 };
            sort(array, 0,array.Length - 1);
            for (int i = 0;i<array.Length;i++)
            {
                Console.WriteLine(array[i]);
            }
            Console.ReadKey();
        }

        private static void sort(int[] array, int low, int high)
        {
            if(low>=high)
            {
                return;
            }
            int midindex=sortUit(array, low, high);
            sort(array, low, midindex-1);
            sort(array, midindex+1,high);
        }

        private static int sortUit(int[] array, int low, int high)
        {
            int key=array[low];
            while(low<high)
            {
                while (array[high]>=key&&high>low)
                {
                    high--;
                }
                array[low] = array[high];
                while (array[low]<=key&&high>low)
                {
                    low++;
                }
                array[high] = array[low];
            }
            array[low] = key;
            return high;
        }
    }
}
